# -*- coding: utf-8 -*-

from core.resources import CustomerModelResource
from import_export.fields import Field
from import_export.widgets import ForeignKeyWidget
from apps.rms.models import ProtocolType, ProtocolField
from apps.pms.models import Product
from apps.rms.protocol.widget import *


class ProtocolTypeResouces(CustomerModelResource):
    product = Field(attribute='product',
                    widget=ForeignKeyWidget(Product, field='name'))

    class Meta:
        model = ProtocolType
        fields = ('name_cn', 'name_en', 'name', 'product', 'type', 'remark')
        import_id_fields = ('name', 'product', )
        export_order = fields


class ProtocolFieldResouces(CustomerModelResource):
    product = Field(attribute='product',
                    widget=ForeignKeyWidget(Product, field='name'))
    protocol = Field(attribute='protocol', widget=ProtocolTypeForeignKeyWidget(
        ProtocolType, field='name'))

    class Meta:
        model = ProtocolField
        fields = ('name_cn', 'name_en', 'name', 'product', 'protocol', 'sdx', 'type', 'length', 'desc', 'tshark', 'isjx',
                  'istl', 'issx', 'remark')
        import_id_fields = ('name', 'protocol', 'product', )
        export_order = fields
